﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace CoreProcess.Utility
{
    public class Md5
    {
        private readonly MD5 _md5;
        private FileStream _fileStream;
        public Md5(FileStream fileStream)
        {
            _md5 = new MD5CryptoServiceProvider();
            _fileStream = fileStream;
        }

        public string GetHashHexString()
        {
            var sb = new StringBuilder();
            foreach (var bt in _md5.ComputeHash(_fileStream))
            {
                sb.Append(Convert.ToString(bt, 16));
            }
            return sb.ToString();
        }

        public byte[] GetHash()
        {
            return _md5.ComputeHash(_fileStream);
        }
    }
}
